jQuery(function() {
	jQuery('#serviceType').val(jQuery('#serviceType1').val());
	jQuery('#revisitTime').val(moment(jQuery('#revisitTime1').val()).format("YYYY-MM-DD"));
	jQuery('#assess').val(jQuery('#assess1').val());
	//////////////////////////客户信息///////////////////////////////////////////////
	//保存客户信息
	function saveAfterSaleReturnVisit(state){
		var revisitTime = jQuery('#revisitTime').val();
		var registrant = jQuery('#registrant').val();
		var managedcode = jQuery('#managedcode').val();
		var contractNumber=jQuery('#contractNumber').val();
		var customerUnit=jQuery('#customerUnit').val();
		var serviceType=jQuery('#serviceType').val();
		var servicer=jQuery('#servicer').val();
		var assess=jQuery('#assess').val();
		var registor=jQuery('#registor').val();
		var phoneNumber=jQuery('#phoneNumber').val();
		var manner=jQuery('#manner').val();
		var quality=jQuery('#quality').val();
		var serviceTime=jQuery('#serviceTime').val();
		var result=jQuery('#result').val();
		var advice=jQuery('#advice').val();
		var solution=jQuery('#solution').val();
		var id=jQuery('#Id').val();
		var url = window.rootPath + "/ui/aftersalereturnvisit/save";
		// 判断是编辑还是新增
		if (id == "") {
			var d = {
				"revisitTime": revisitTime,
				// "createTime":createTime,
				"registrant":registrant,
				"managedcode": managedcode,
				"contractNumber": contractNumber,
				"customerUnit": customerUnit,
				"serviceType": serviceType,
				"servicer": servicer,
				"registor": registor,
				"phoneNumber": phoneNumber,
				"manner": manner,
				"quality": quality,
				"serviceTime": serviceTime,
				"result": result,
				"advice": advice,
				"solution": solution,
				"assess": assess,

			};

		} else {
			var d = {
				"id" : id,
				"revisitTime": revisitTime,
				// "createTime":createTime,
				"registrant":registrant,
				"managedcode": managedcode,
				"contractNumber": contractNumber,
				"customerUnit": customerUnit,
				"serviceType": serviceType,
				"servicer": servicer,
				"registor": registor,
				"phoneNumber": phoneNumber,
				"manner": manner,
				"quality": quality,
				"serviceTime": serviceTime,
				"result": result,
				"advice": advice,
				"solution": solution,
				"assess": assess,

			};
		}
		jQuery(".btn").attr("disabled", true);
		jQuery.ajax({
			type: 'post',
			url:  encodeURI(url),
			data: JSON.stringify(d),
			dataType: 'json',
			contentType: 'application/json;charset=utf-8',
			success: function (data) {
				jQuery(".btn").attr("disabled", false)
				if(state=='saveBtn'){
					window.location = window.rootPath+"/ui/aftersalereturnvisit";}
                else if(state=='upload'){
					var returnvisitId = data.afterSaleReturnVisit.id;
					jQuery('#Id').val(returnvisitId);
					fileUpload( returnvisitId, "电话回访附件",null,'attachmentnumber');
				}


			}

		});
	}
	// 保存客户信息
	jQuery('.saveBtn').on('click', function() {
		if (jQuery("#returnVisitAddModal") && !jQuery("#returnVisitAddModal").Validform({
				tiptype : 3,
				showAllError : true
			}).check(false)) {
			return;
		};
		saveAfterSaleReturnVisit('saveBtn');
	});

// 上传附件
	jQuery(".upload").on('click', function() {
		var returnvisitId = jQuery("#Id").val();
		if ( returnvisitId == '') {
			if (jQuery("#returnVisitAddModal") && !jQuery("#returnVisitAddModal").Validform({
					tiptype : 3,
					showAllError : true
				}).check(false)) {
				return;
			}
			;
			$.springLemonDialog({
				content : '将保存电话回访附件，是否继续',// 确认文本
				clickButton : function(sender, modal, index) {// 按钮事件处理
					if (index == 0) {
						saveAfterSaleReturnVisit('upload');
					}
					$(this).closeDialog(modal);
				}
			});
		} else {
			fileUpload( returnvisitId, "电话回访附件",null,'attachmentnumber');
		}
	});
  // 下载附件
	jQuery(".download").on('click', function() {
		var  returnvisitId = jQuery("#Id").val();
		filedown( returnvisitId, '电话回访附件',1);
	});
    //获附件数量
	var returnvisitId = jQuery("#Id").val();
	var numId='attachmentnumber';
	if(returnvisitId !=''){
		showANum(returnvisitId,'电话回访附件',numId);
	}
	
});
